window.onload=function () {
    var app = new Vue({
        el: "#app",
        data: {
            pagination: {
                total: 0, //总记录数
                pageSize: 10, //每页的记录数
                pageNum: 1, //当前页码
            },
            myanswerarray:[],//所有回答
            lookmyanswerno:false,//查看弹出框
            updatemyanswerbox:false,//修改弹出框
            myanswer:{
                aaid:"",//回答id
                uname:"",//发布用户
                state:"",//状态
                reasons:"",//原因
                aid:0
            },
            state:"",
            options:[{
                value:'1',
                label: '审核中'},
                {
                    value:'2',
                    label: '未通过'},
                {
                    value:'0',
                    label: '已删除'}
            ]
        },
        methods: {
            inisanswer(){
                //初始化数据
                methodaxios.get(null,"/answer/listno?currentPage="+this.pagination.pageNum+"&pageSize="+this.pagination.pageSize+"&state="+this.state,rep=>{
                    window.console.log("回答================================");
                    window.console.log(rep)
                    window.console.log(rep.data.data);
                    this.myanswerarray=rep.data.data;
                    this.pagination.total=rep.data.count;
                });
            },//当前页发送改变
            findBlogPageList(page) {
                //页数改变
                this.pagination.pageNum = page;
                this.inisanswer();
            }, //每页大小发送改变
            sizeChange(size) {
                this.pagination.pageSize = size; //当前页显示多少
                this.pagination.pageNum = 1;
                this.inisanswer();
            },//点击搜索
            searchanswer(){
                //this.pagination.pageSize = size; //当前页显示多少
                this.pagination.pageNum = 1;
                this.inisanswer();
            },
            resetanswers(){
                this.state=""
                // this.pagination.pageSize = size; //当前页显示多少
                this.pagination.pageNum = 1;
                this.inisanswer();
            },
            wantlookmyanswer(row){//用户点击查看
                var E = window.wangEditor
                var editor = new E('#editor')
                editor.create()
                this.lookmyanswerno=true
                this.myanswer.uname=row.uname;
                editor.$textElem.attr('contenteditable', false)
                editor.txt.html('<p>' +row.aa_content+'</p>' );
            },
            updatemyanswer(row){//点击修改按钮
                this.myanswer.aaid=row.aaid;
                this.myanswer.uname=row.uname;
                this.myanswer.state=row.state;
                this.myanswer.reasons=row.reasons;
                this.myanswer.aid=row.aid;
                this.updatemyanswerbox=true
                var E = window.wangEditor
                var editor = new E('#updateeditoranswer')
                editor.create()
                editor.$textElem.attr('contenteditable', false)
                editor.txt.html('<p>' +row.aa_content+'</p>' );
            },
            confirmupdatemyanswer(){//确定修改
                if(isBlank(this.myanswer.state)){
                    layer.msg("请指定状态");
                    return false;
                }
                if(isBlank(this.myanswer.reasons)){
                    layer.msg("请填写问答描述");
                    return false;
                }
                methodaxios.post("/answer/updateno",this.myanswer,rep=>{
                    if(rep.data.code==="200"){
                        this.myanswer.reasons=""
                        this.myanswer.state=""
                        layer.msg("修改成功");
                        this.updatemyanswerbox=false
                        this.inisanswer();
                    }
                });
            }
        },mounted(){
            this.inisanswer();
        },
        filters:{
            mytime(value){
                var dateee = new Date( value).toJSON();
                return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
            },//状态(0 伪删除 1审核中 2通过 3未通过)
            mystate(value){
                if(value=="0"){
                    return "已删除"
                }else if(value=="1"){
                    return "审核中"
                }else if(value=="2"){
                    return "未通过"
                }
            }
        }

    })
}
